# Paths
GENSCAT  = ../..
TOOLS    = ..

GENSTS   = $(GENSCAT)/stress
GENSUP   = $(GENSCAT)/support
GENBIN   = $(GENSUP)/binning
GENBUF   = $(GENSUP)/bufr
GENCON   = $(GENSUP)/convert
GENCPF   = $(GENSUP)/Compiler_Features
GENERR   = $(GENSUP)/ErrorHandler
GENNUM   = $(GENSUP)/num
GENTIM   = $(GENSUP)/datetime
GENSTA   = $(GENSUP)/statistics
GENSWAT  = $(GENSCAT)/tools/swat
TOOLS_BUFR_L2_RDR = $(TOOLS)/bufr_l2_reader

# General settings and compiler options
include   $(GENSCAT)/Makeoptions

MYF90FLAGS = 

# Targets in this directory
all:    BuoyRead BuoyCollocate BuoyColl2Bin CollocationStatistics BuoyColl2BinL3

again:
	@$(MAKE) clean; $(MAKE)

clean:
	@$(RM) $(RMFLAGS) *.mod *.o *~ BuoyRead BuoyCollocate BuoyColl2Bin \
                                       CollocationStatistics BuoyColl2BinL3

# Targets outside this directory
$(GENBIN)/binning.o:
	-@cd $(GENBIN); $(MAKE) binning.o

$(GENBUF)/BufrMod.o:
	-@cd $(GENBUF); $(MAKE) -f Makefile_thisdir BufrMod.o

$(GENBUF)/bufrio.o:
	-@cd $(GENBUF); $(MAKE) -f Makefile_thisdir bufrio.o

$(GENBUF)/libbufr.a:
	-@cd $(GENBUF); $(MAKE) -f Makefile_thisdir libbufr.a

$(GENCON)/convert.o:
	-@cd $(GENCON); $(MAKE) convert.o

$(GENCPF)/Compiler_Features.o:
	-@cd $(GENCPF); $(MAKE) Compiler_Features.o

$(GENERR)/ErrorHandler.o:
	-@cd $(GENERR); $(MAKE) ErrorHandler.o

$(GENNUM)/numerics.o:
	-@cd $(GENNUM); $(MAKE) numerics.o

$(GENTIM)/DateTimeMod.o:
	-@cd $(GENTIM); $(MAKE) DateTimeMod.o

$(GENSTS)/windstress.o:
	-@cd $(GENSTS); $(MAKE) windstress.o

$(GENSTA)/statistics.o:
	-@cd $(GENSTA); $(MAKE) stat.o
	-@cd $(GENSTA); $(MAKE) moments.o

$(GENSWAT)/SWAT_Module.o:
	-@if [ -d $(GENSWAT) ] ; then \
          cd $(GENSWAT); $(MAKE) SWAT_Module.o ; \
        fi
$(TOOLS_BUFR_L2_RDR)/bufr_data_extraction_module.o:
	-@cd $(TOOLS_BUFR_L2_RDR); $(MAKE) bufr_data_extraction_module.o

# Includes
INC =   $(MODINCFLAG)$(GENBIN) \
        $(MODINCFLAG)$(GENBUF) \
        $(MODINCFLAG)$(GENCON) \
        $(MODINCFLAG)$(GENCPF) \
        $(MODINCFLAG)$(GENERR) \
        $(MODINCFLAG)$(GENNUM) \
        $(MODINCFLAG)$(GENTIM) \
        $(MODINCFLAG)$(GENSTS) \
        $(MODINCFLAG)$(GENSTA) \
        $(MODINCFLAG)$(GENSWAT) \
        $(MODINCFLAG)$(TOOLS_BUFR_L2_RDR)

# Objects
OBJ =   $(GENBIN)/binning.o \
        $(GENBUF)/BufrMod.o \
        $(GENBUF)/bufrio.o \
        $(GENCON)/convert.o \
        $(GENCPF)/Compiler_Features.o \
        $(GENERR)/ErrorHandler.o \
        $(GENNUM)/numerics.o \
        $(GENTIM)/DateTimeMod.o \
        $(GENSTS)/windstress.o \
        $(GENSTA)/stat.o \
        $(GENSTA)/moments.o \
        $(TOOLS_BUFR_L2_RDR)/bufr_data_extraction_module.o

OBJ2 =  $(OBJ) \
        $(GENSWAT)/SWAT_Module.o

# Libraries
LIB =   $(GENBUF)/libbufr.a

# Dependencies
BuoyRead.o:      BuoyRead.F90 $(OBJ) $(LIB)

BuoyCollocate.o: BuoyCollocate.F90 $(OBJ) $(LIB)

BuoyColl2BinL3.o: BuoyColl2BinL3.F90 $(OBJ) $(LIB)

BuoyColl2Bin.o:  BuoyColl2Bin.F90 $(OBJ)

CollocationStatistics.o: CollocationStatistics.F90 $(OBJ2)

BuoyRead:        BuoyRead.o
	$(LINK) $(OBJ) $(LINKFLAGS) $(MYLINKFLAGS) $@.o -o $@

BuoyCollocate:   BuoyCollocate.o
	$(LINK) $(OBJ) $(LINKFLAGS) $(MYLINKFLAGS) $@.o -o $@

BuoyColl2BinL3:   BuoyColl2BinL3.o
	$(LINK) $(OBJ) $(LINKFLAGS) $(MYLINKFLAGS) $@.o -o $@

BuoyColl2Bin:    BuoyColl2Bin.o
	$(LINK) $(OBJ) $(LINKFLAGS) $(MYLINKFLAGS) $@.o -o $@

CollocationStatistics:  CollocationStatistics.o
	$(LINK) $(OBJ2) $(LINKFLAGS) $(MYLINKFLAGS) $@.o -o $@

